package com.chen.authority.controller;

import com.chen.authority.common.response.MultiResponse;
import com.chen.authority.common.response.SingleResponse;
import com.chen.authority.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 首页图表数据 OpenApi
 *
 * @author chengy
 * @date 2022/11/19
 */
@RestController
@RequestMapping("/index")
@RequiredArgsConstructor
@Api(tags = "首页图表数据 IndexController")
public class IndexController {

    private final IndexService indexService;
    private final OnlineUserService onlineUserService;

    @GetMapping("/panel-group")
    @ApiOperation("获取面板组数据")
    public SingleResponse<Map<String, Object>> panelGroupData() {
        Map<String, Object> map = indexService.findUserDeptPostCount();
        map.put("onlineUserCount", onlineUserService.getOnlineUserCount());
        return SingleResponse.success(map);
    }

    @GetMapping("/line/cycle")
    @ApiOperation("获取登录及操作周期数据")
    public SingleResponse<Map<Object, Object>> loginAndOperation() {
        return SingleResponse.success(indexService.getLoginAndOperationCycleData());
    }

    @GetMapping("/pie/user-sex")
    @ApiOperation("获取用户性别比例数据")
    public MultiResponse<Map<String, Integer>> userSexProportion() {
        return MultiResponse.success(indexService.findUserSexProportionList());
    }

    @GetMapping("/pie/department")
    @ApiOperation("获取部门人数比例数据")
    public MultiResponse<Map<String, Integer>> departmentProportion() {
        return MultiResponse.success(indexService.findDepartmentPeopleProportionList());
    }

    @GetMapping("/pie/post")
    @ApiOperation("获取岗位人数比例数据")
    public MultiResponse<Map<String, Integer>> postProportion() {
        return MultiResponse.success(indexService.findPostPeopleProportionList());
    }

}